<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .header {
            height: 70px;
            background-color: #f8f8f8;
        }

        .header-left {
            width: 50%;
            line-height: 70px;
            text-align: center;
            float: left;
        }

        .header-right {
            width: 50%;
            float: left;
            line-height: 70px;
            text-align: center;
        }

        .gallery-text {
            color: black;
            text-decoration: none;
            font-family: "Arial", "Microsoft YaHei", "黑体", "宋体", sans-serif;
            font-size: 20px;
            letter-spacing: 2px;
        }

        .logo {
            margin-top: -10px;
        }

        .dropdown-menu {
            background-color: #f8f8f8;
        }

        .title-box {
            width: 60%;
            margin-top: 7%;
            margin-left: 20%;
            color: #000000;
            text-align: center;
        }

        .footer {
            height: 200px;
            background-color: #f8f8f8;
        }

        #about {
            width: 50%;
            height: 150px;
            float: left;
            text-align: center;
        }

        #link {
            width: 50%;
            height: 150px;
            float: left;
            text-align: center;
        }

        #link ul {
            text-align: left;
            margin-left: 20%;
        }

        #link ul li {
            list-style: none;
        }

        .copy-right {
            line-height: 50px;
            text-align: center;
        }

        .container {
            height: 800px;
            width: 100%;
            background: url("/images/bg.jpg") no-repeat;
            background-size: 100% 100%;
        }

        .modal-body {
            height: 600px;
        }

        .signinbox-v2_header {
            height: 150px;
            text-align: center;
            line-height: 150px;
        }

        #input {
            height: 200px;
            width: 70%;
            margin-left: 15%;
        }

        #login {
            margin-top: 50px;
            height: 200px;
        }

        #logo {
            margin-top: -15px;
        }

        label.error {
            color: red;
        }
    </style>
</head>
<#include "public/head.ftl"/>

<div class="container">
</div>

<div class="modal show" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <div class="form-wrap">
                    <div class="row">
                        <div class="form site-block">
                            <form action="/user/password/reset" accept-charset="UTF-8" method="post">
                                <div class="signinbox-v2_header text-center">
                                    <a href="/">
                                        <img src="/images/logo.png" id="logo">
                                        <h2 style="color: black; display: inline-block">YIHUU</h2>
                                    </a>
                                </div>
                                <div id="input">
                                    <div class="form-group" id="phone">
                                        <div class="col-xs-12">
                                            <div class="input-groups">
                                                <label class="control-label">Name</label>
                                                <input id="user_phone" class="form-control" placeholder="请输入用户名重置密码"
                                                       name="uname" type="text">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group password" id="question-box">
                                        <div class="col-xs-12">
                                            <div class="input-groups">
                                                <label class="pull-left control-label">Question</label>
                                                <input id="question" class="form-control" name="question"
                                                       type="text" readonly>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group password" id="answer-box">
                                        <div class="col-xs-12">
                                            <div class="input-groups">
                                                <label class="pull-left control-label">Answer</label>
                                                <input id="answer" class="form-control" name="answer"
                                                       type="text">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group password" id="password-box" style="display: none">
                                        <div class="col-xs-12">
                                            <div class="input-groups">
                                                <label class="pull-left control-label">Password</label>
                                                <input id="password"  class="form-control" name="upassword"
                                                       type="password">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group password" id="confirm-password-box" style="display: none">
                                        <div class="col-xs-12">
                                            <div class="input-groups">
                                                <label class="pull-left control-label">Confirm</label>
                                                <input  class="form-control" name="upwd"
                                                       type="password">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group login" id="login">
                                    <div class="col-xs-12 text-center">
                                        <input type="submit" class="btn  btn-primary btn-lg" value="确定"
                                               style="width: 200px ">
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<#include "public/footer.ftl">

<script>
    $(function () {
        $("form").validate({
            debug: false,
            onkeyup: true,
            rules: {
                uname: {
                    required: true,
                    rangelength: [5, 15],
                    remote: {
                        url: "/user/check",
                        type: "post",
                        dataType: "json",
                        data: {
                            "type": "uname"
                        }
                    }
                },
                answer: {
                    required: true
                },
                upassword:{
                    required:true,
                    rangelength: [10, 20],
                },
                upwd:{
                    required:true,
                    equalTo:"#password"
                }
            },
            messages: {
                uname: {
                    required: "用户名不能为空",
                    rangelength: "用户名长度必须为{0}和{1}之间",
                    remote: "用户名不存在"
                },
                answer: {
                    required: "答案不能为空"
                },
                upassword:{
                    required: "密码不能为空",
                    rangelength: "密码长度必须为{0}和{1}之间"
                },
                upwd:{
                    required: "确认密码不能为空",
                    equalTo:"两次输入不一致"
                }
            }
        });

        $("#user_phone").blur(function () {
            $.ajax({
                url: "/user/question",
                type: "post",
                data: {
                    "uname": $("#user_phone").val()
                },
                dataType: "json",
                success: function (result) {
                    $("#question").val(result.data);
                }
            });
        });

        $("#answer").blur(function () {
            $.ajax({
                url: "/user/answer/confirm",
                type: "post",
                data: {
                    "uname": $("#user_phone").val(),
                    "question": $("#question").val(),
                    "answer": $("#answer").val()
                },
                dataType: "json",
                success: function (result) {
                    if (result.data) {
                       $("#password-box").show();
                       $("#confirm-password-box").show();
                    } else {
                        alert("答案输入错误");
                    }
                }
            });
        });
    });
</script>